<?php
class attend {
	function getCheckUnits() {
		global $lang;

		$cacheinfo = getmodelinfoall('modelname', 'shop');

		$checkunits = array(
			array('subject', '2', '30', $lang['attend_subject_error']),
			array('address', '5', '30', $lang['attend_address_error'])
		);
		if(!empty($cacheinfo['columns'])) {
			foreach($cacheinfo['columns'] as $column) {
				if($column['allowpost'] == 1 && $column['allowshow'] == 1 && $column['formtype'] != 'img' && $column['isrequired'] == 1 && preg_match('/(^ext_)|(^applicant)/',$column['fieldname'])) {
					$errormessage = !empty($lang['attend_'.$column['fieldname'].'_error']) ? $lang['attend_'.$column['fieldname'].'_error'] : ($column['fieldminlength'] < $column['fieldlength'] ? $column['fieldtitle'].$lang['is'].$column['fieldminlength'].'-'.$column['fieldlength'].$lang['word'] : $column['fieldlength'].$lang['word']);
					array_push($checkunits, array($column['fieldname'], $column['fieldminlength'], $column['fieldlength'], $errormessage));
				}
			}
		}
		return $checkunits;
	}
	function registerUser($username, $password, $email) {
		global $_G, $lang;
		$member = array('username'=>$username, 'password'=>$password, 'email'=>$email);

		$uid = uc_user_register($username, $password, $email);

		if ($uid < 0) {
			switch ($uid) {
				case -1:
					$_G['ajax_errors'][] = array('username'=>$lang['user_name_is_not_legitimate']);
					break;
				case -2:
					$_G['ajax_errors'][] = array('username'=>$lang['include_not_registered_words']);
					break;
				case -3:
					$_G['ajax_errors'][] = array('username'=>$lang['user_name_already_exists']);
					break;
				case -4:
					$_G['ajax_errors'][] = array('email'=>$lang['email_format_is_wrong']);
					break;
				case -5:
					$_G['ajax_errors'][] = array('email'=>$lang['email_not_registered']);
					break;
				case -6:
					$_G['ajax_errors'][] = array('email'=>$lang['email_has_been_registered']);;
					break;
				default:
					$_G['ajax_errors'][] = array('message'=>$lang['register_error']);
			}
		}
		display_errors('applicant_info_failed');
		if ($uid > 0) {
			$member['uid'] = $uid;
			$member['dateline'] = $_G['timestamp'];
			$member['password'] = md5($password);
			$shop = DB::fetch_first("select * from " . DB::table("members") . " where uid=".$uid);
			if (!$shop) {
				inserttable('members',$member,1);
			}
		}
		return $member;
	}
	function sendMsg() {
		global $_G, $_SC, $lang;
		uc_pm_send(0, $_SC['founder'] , $lang['apm_admin_title'] , $lang['apm_admin_msg']);
		uc_pm_send(0 , $_G['uid'] , $lang['apm_panel_title'] , $lang['apm_panel_msg']);
	}
}

?>